package com.qingcheng.controller.goods;


import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Brand;
import com.qingcheng.service.goods.BrandService;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Reference
    private BrandService brandService;

    @RequestMapping("/findAll")
    public List<Brand> findAll()
    {
        return brandService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Brand> findPage(int page,int size)
    {
        return brandService.findPage(page,size);
    }
//条件查询
    @PostMapping("/findList")
    public List<Brand> findList(@RequestBody Map searchMap){
        return brandService.findList(searchMap);
    }

//    条件分页查询
    @PostMapping("/findPage")
//    @RequestBody 在post请求下，前台传过来map集合，需要把集合解析成json
    public PageResult<Brand> findPage(@RequestBody Map searchMap,int page,int size) {
       return brandService.findPage(searchMap,page,size);


    }

    @GetMapping("/findById")
    public Brand findById(int id)
    {
        return brandService.findById(id);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Brand brand)
    {
//        int x=1/0;
        brandService.add(brand);

        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Brand brand) {
        brandService.update(brand);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(int id) {
        brandService.delete(id);
        return new Result();
    }
}
